{
LANG : PASCAL
PROB : dualpal
}

program DUALPAL;
const
  fi = 'dualpal.in';
  fo = 'dualpal.out';
  max = 1000;
var
  n, s : longint;

function palin(s, k : longint) : boolean;
var
  a : array[1..max] of integer;
  i, l : integer;
begin
  l := 0;
  while s > 0 do
  begin
    inc(l);
    a[l] := s mod k;
    s := s div k;
  end;
  palin := false;
  for i := 1 to l div 2 do
    if a[i] <> a[l-i+1] then exit;
  palin := true;
end;

procedure process;
var
  i, sum : integer;
  ok : boolean;
begin
  inc(s);
  while n > 0 do
    while true do
    begin
      sum := 0;
      ok := false;
      for i := 2 to 10 do
        if palin(s, i) then
        begin
          inc(sum);
          if sum = 2 then
          begin
            ok := true;
            writeln(s);
            dec(n);
            break;
          end;
        end;
      inc(s);
      if ok then break;
    end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(n, s);
  process;
  close(output);
  close(input);
end.